
//  ========== 
//  = Map = 
//  ========== 
/*
 * 创建对象         var map = Map.createNew();
 * 设置labelid        map.Labelid("a");
 * 创建SVG            map.CreateSvg();
 * 绘制                   map.Draw();
 * 
 * 未来：
 *      ===;
 * */
! function() {
    var Map = Object.create(Object);
    Object.defineProperty(Map, "createNew", {
        value: function() {
            return FCreateNew();
        }

    });

    function FCreateNew() {
        var map = Object.create(Map);
        console.log("?");
        //定义_labelid的属性
        var labelid_value;
        Object.defineProperty(map, "_labelid", {
            get: function() {
                return labelid_value;
            },
            set: function(v) {
                labelid_value = v;
            }
        });

        //定义设置_labelid属性的方法
        Object.defineProperty(map, "Labelid", {
            value: function(v) {
                this._labelid = v;
                return this;
            }
        });
        //定义_width的属性
        var width_value;
        Object.defineProperty(map, "_width", {
            get: function() {
                return width_value;
            },
            set: function(v) {
                width_value = v;
            }
        });

        //定义设置_width属性的方法
        Object.defineProperty(map, "Width", {
            value: function(v) {
                this._width = v;
                return this;
            }
        });
        //定义_height的属性
        var height_value;
        Object.defineProperty(map, "_height", {
            get: function() {
                return height_value;
            },
            set: function(v) {
                height_value = v;
            }
        });

        //定义设置_height属性的方法
        Object.defineProperty(map, "Height", {
            value: function(v) {
                this._height = v;
                return this;
            }
        });

        //定义创建svg方法
        Object.defineProperty(map, "CreateSvg", {
            value: function() {
                CreateSvg_map(this);
                return this;
            }
        });
        //定义设置Draw方法
        Object.defineProperty(map, "Draw", {
            value: function() {
                draw_map(this);
            }
        });

        CreateSvg_map = function(map) {
                //createSvg之前先判断map各属性
                DetermineProperties_map(map);
                map.svg = d3.select("#"+map._labelid)
                .append("svg")
                .style("background","red")
                .attr("id", map._svgid)
                .attr("preserveAspectRatio", "xMidYMid meet")
                .attr("viewBox", "0 0 " + map._width + " " + map._height + " ");
//              .attr("width",map._width)
//              .attr("height",map._height);
                map.svg_ceshi1_g = map.svg.append("g").attr("id",map._svg_ceshi1_gid);
                map.svg_ceshi2_g = map.svg.append("g").attr("id",map._svg_ceshi2_gid);
            }
            //  ========== 
            //  = 判断属性 = 
            //  ========== 
        Detect_function_map = function(object_lh) {
            return typeof(object_lh) == "undefined";
        }
        DetermineProperties_map = function(map) {
            console.log(map._labelid);
            Detect_function_map(map._labelid) ?
                console.log("父容器id呢") :
                d3.select("#" + map._labelid)[0][0] == null ?
                console.log("请检查id是否正确") :
                SetId_map(map);
            map._width = Detect_function_map(map._width) ? $("#" + map._labelid).width() : map._width;
            map._height = Detect_function_map(map._height) ? (map._width > 500) ? 500 : map._width : map._height;
        }
        SetId_map = function(map) {
            map._svgid = map._labelid + "svg";
            map._svg_ceshi1_gid = map._labelid + "svg_ceshi1_g";
            map._svg_ceshi2_gid = map._labelid + "svg_ceshi2_g";
        }
        return map;
    };
    this.Map = Map;
}();